<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<div id="app">
			<cpn></cpn>
		</div>
	</body>
	<template id="cpn">
		<div>
			<div>我是子组件</div>
			<button type="button" @click="btnClick">按钮</button>
			<ccpn></ccpn>
		</div>
	</template>
	
	<template id="ccpn">
		<div>
			<div>我是孙组件</div>
			<button type="button" @click="btnClick">按钮</button>
		</div>
	</template>
	
	<script src="../js/vue.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		const ccpn = {
			template: '#ccpn',
			methods:{
				btnClick(){
					// 1. 访问父组件$parent
					console.log(this.$parent);
					// this.$parent.showMessage();
					console.log(this.$parent.name);
					// this.$parent.name;
					// 2.访问根组件$root
					console.log(this.$root.name);
				}
			},
			data(){
				return {
					name : "子子组件"
				}
			}
		}
	
		const cpn = {
			template: '#cpn',
			methods:{
				btnClick(){
					// 1. 访问父组件$parent
					console.log(this.$parent);
					this.$parent.showMessage();
				}
			},
			data(){
				return {
					name : "子组件"
				}
			},
			components:{
				ccpn
			}
		}
		
		
		const app = new Vue({
			el : "#app",
			data:{
				name : "根组件"
			},
			methods:{
				showMessage(){
					console.log("showMessage");
				}
			},
			components:{
				cpn
			}
		})
	</script>
</html>
